(function($) {
	'use strict';
	$(function(){
		$.maoutil = {
				formatNumber:function(num,decimal){
					decimal = decimal > 0 && decimal <= 20 ? decimal : 2;   
					num = parseFloat((num + "").replace(/[^\d\.-]/g, "")).toFixed(decimal) + "";
					var l = num.split(".")[0].split("").reverse(),
					r = num.split(".")[1];
					var t = "";
					for(var i = 0; i < l.length; i ++ ) {
					      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
					}
					return t.split("").reverse().join("") + "." + r;
				}
		};
		Handlebars.registerHelper("url",function(){
			  var params = [];
			  for (var i = 0;i<arguments.length - 1;i++){
				  params.push(arguments[i]);
			  }
			  return $.config.base+params.join("");
		});
		Handlebars.registerHelper("imgurl",function(v,w,h){
			if (w && h){
				v = v+"@"+w+"w_"+h+"h_1c_1e";
			} else if (w){
				v = v+"@"+w+"w";
			} else if (h != 0){
				v = v+"@"+h+"h";
			}
			return $.config.image+v;
		});
		Handlebars.registerHelper("multi",function(v1,v2){
			  return v1 * v2;
		});
		
		Handlebars.registerHelper("fnumber",function(num,decimal){
			return $.maoutil.formatNumber(num,decimal);
		});
		Handlebars.registerHelper("multi-fnumber",function(num1,num2,decimal){
			  return $.maoutil.formatNumber(num1 * num2,decimal);
		});
		//屏蔽右键
		document.oncontextmenu = function(){return false;};
		
		//计算m-content的距离，避免一些浏览器不支持calc
		if (!$("#m-main").hasClass("home")){
			var mainWidth = $("#m-main").width();
			var contentWidth = $("#m-content").width();
			var sidebarWidth = $("#m-sidebar").innerWidth();
			if (contentWidth > (mainWidth - sidebarWidth)){
				 $("#m-content").width(mainWidth - sidebarWidth);
			}
		}
	});
})(jQuery);

(function($) {
  'use strict';
 
  $(function() {
    var $fullText = $('.admin-fullText');
    $('#admin-fullscreen').on('click', function() {
      $.AMUI.fullscreen.toggle();
    });

    if ($.AMUI.fullscreen){
    	$(document).on($.AMUI.fullscreen.raw.fullscreenchange, function() {
    	    $.AMUI.fullscreen.isFullscreen ? $fullText.text('关闭全屏') : $fullText.text('开启全屏');
    	});
    }
  });
  
  //导航栏的处理
  $(function(){
	  $(".m-sidebar-sub").on("open.collapse.amui",function(){
			$(this).closest(".m-parent").find(".collapse-icon").html("&minus;");
	  });
	  $(".m-sidebar-sub").on("close.collapse.amui",function(){
			$(this).closest(".m-parent").find(".collapse-icon").text("+");
	  });
  });
  //通知
  $(function(){
	  var content = $("#notice-tpl").html();
	  var tpl="<div class='am-popover m-notice-popover'><div class='am-popover-inner m-notice-popover-inner'></div><span class='am-close close-btn'>&times;<span></div>"
	  var popover = $(".m-nav-notice").popover({
		    content: content,
		    trigger:'click',
		    tpl:tpl,
		    popTop:function(){
//		    	console.log($("#m-header-hd").height());
		    	return $("#m-header").height()+1;
		    }
	  });
	  $(".m-nav-notice").on("open.popover.amui",function(){
		  $(".m-notice-popover").css("opacity",0.85);
	  });
	  $(document)
	  	.on("click.notice",".m-nav-notice,.m-notice-popover,.m-notice-popover .close-btn",function(e){
	  		//如果是popover的关闭按钮，则直接关闭
	  		if (!$(e.target).hasClass("close-btn")){
	  			e.stopPropagation();
	  		}
	  	})
	  	.on("click.notice",function(){
		  $(".m-nav-notice").popover("close");
	  });
  });
  
  $(function(){
	  $(document).on("click","#login",function(){
		  $.user.login();
	  });
  });
  
 
  //登录信息
  //注册信息
  //购物车处理
  
})(jQuery);

(function($) {
	  'use strict';
	  
	  $(function(){
		  var $dialog = $("#dialog");
		  //$("<div/>").boxer();
		  
		  $(document).on("click","#forgot-password",function(){
			  $.user.forgot();
			  $.phoneVerifyCode({
				  target:"#forgot-code button",
				  phone:"#forgot-mobile input",
				  error:"#forgot-mobile .m-field-error",
				  form:"#forgot-form"
			  });
		  });
		  $(document).on("click","#register-btn",function(){
			  $.user.register();
			  //注册验证码
			  $.phoneVerifyCode({
				  target:"#register-code button",
				  phone:"#register-mobile input",
				  error:"#register-mobile .m-field-error",
				  form:"#register-form"
			  });
		  });
		  $(document).on("click","#close-boxer-btn",function(){
//			  $.boxer("close");
			  $("#dialog").modal('close');
		  });
		  var formInit = function(formSelector,successFn,errorFn){
			  var $form = $(formSelector);
			  var $error = $form.find(".m-form-error");
			  var $submit = $form.find("button");
			  $form.validate(function($form,errors,events){
				  $error.html("");
				  if (errorFn){
					  errorFn($form,errors,events);
				  } else {
					  $.each(errors,function(i,e){
							$error.append(e.message+"<br>");
					  });
					  //$.boxer("resize");
				  }
			  });
			  var options = {
			            beforeSubmit:function(){
			            	$submit.button('loading');
			            },
			            success: function (data) {
			            	$submit.button('reset');
				            //成功
				            if (data.success){
				            	//刷新当前页面
				            	successFn(data);
				            } else {
				            	if (errorFn){
				            		errorFn($form,data.errors);
				            	} else {
				            		$error.html(data.error);
					            	//$.boxer("resize");
				            	}
					        }
			            }
			   };
			   $form .ajaxForm(options);
		  }
	
		  $.user = {
				  check:function(){
					  if ($.config.login){
						  $(".m-nav-user").html("<a href='"+$.config.base+"user'><span id='user' class='m-login-user-btn'>" + $.config.user+"</span></a><a href= '"+$.config.base+"logout'><span class='m-logout-btn'>退出</span></a>");
					  }
					  
					  if ($.config.showLogin == "1"){
						  $.user.login();
					  }
				  },
				  login:function(){
					  var content = $("#login-tpl").html();
					  //$dialog.find(".am-modal-bd").html(content);
					  //$dialog.modal({width:760});
					  /*
					  $.boxer($(content),{
						  customClass:"m-dialog-mobile",
						  callback:function(){
						  formInit("#login-form",function(){
							  window.location.reload();
						  });
					  }});*/
					 
					  var $dialogBody = $("#dialog").find(".am-modal-bd");
					  $dialogBody.html(content);
					  formInit("#login-form",function(data){
						  if (data.intended){
							  window.location.href = data.intended;
						  } else {
							  window.location.reload();
						  }
						  
					  });
					  $('#dialog').modal({});
				  },
				  forgot:function(){
                      var $content =  $(".m-login").find(".m-login-bd");
					  var content = $("#forgot-tpl").html();
					  $content.html(content);
					  formInit("#forgot-form",function(data){
						  $content.html($("#message-tpl").html());
						  //$.boxer("resize");
					  },function($form,errors){
						  $form.find(".m-field-error").html("");
						  if ($.isArray(errors)){
							  $.each(errors,function(i,e){
								  var $msg = $(e.element).parent().find(".m-field-error");
								  $msg.html(e.message);
							  });
						  } else {
							  for (var key in errors){
								  var $ele = $form.find("#"+key).parent().find(".m-field-error");
								  $ele.html(errors[key][0]);
							  }
						  }
					  });
				  },
				  register:function(){
					  var content = $("#register-tpl").html();
					  var $content =  $(".m-login");
					  $content.html(content);
					  $("#dialog").css('marginTop',-parseInt($("#dialog").height() / 2, 10) + 'px');
//					  style.marginTop = -parseInt($element.height() / 2, 10) + 'px';
//					  $.boxer("resize");
					  formInit("#register-form",function(data){
						  var $content =  $(".m-login").find(".m-login-bd");
						  var $msgcontent = $($("#message-tpl").html());
						  $msgcontent.find("h3").text("注册成功");
						  $msgcontent.find(".m-message").html("感谢您注册<span class='georgia'>MAGGIEMAO</span>蔓茂花廊，点击登录按钮即可登录。");

//						  $msgcontent.find(".m-message").html("感谢您注册<span class='georgia'>MAGGIEMAO</span>蔓茂花廊，您即将收到一封电子邮件，请前往您的邮箱点击激活链接。");
						  $content.html($msgcontent);
						  //$.boxer("resize");
					  },function($form,errors){
						  $form.find(".m-field-error").html("");
						  if ($.isArray(errors)){
							  $.each(errors,function(i,e){
								  var $msg = $(e.element).parent().find(".m-field-error");
								  $msg.html(e.message);
							  });
						  } else {
							  for (var key in errors){
								  var $ele = $form.find("#"+key).parent().find(".m-field-error");
								  $ele.html(errors[key][0]);
							  }
						  }
					  });
				  }
		  }
		  
		  //检查user是否登录
		  $.user.check();
	  });
	 
})(jQuery);
(function($,window) {
	  'use strict';
	  var $win = $(window);
	  var CART_NAME = "cart.maggiemaostudio";
	  var cookieHelper = $.AMUI.utils.cookie;
	  var domain = window.document.domain;
	  if (domain.indexOf("localhost") >=0){
		  domain = "";
	  }
	  $.cart = {
			  add:function(product){
				  var list = this.list();
				  product["quantity"] = 1;
				  //{id,name,enname,image,fullImage,size,color,quantity,price}
				  var exist = this.match(product,list);
				  if (exist){
					  exist.quantity++;
					  this.store(list);
					  this.trigger("add", product);
				  } else {
					  list.push(product);
					  this.store(list);
					  this.trigger("add", product);
				  }
				  return list;
			  },
			  increment:function(product){
				  var list = this.list();
				  var exist = this.match(product,list);
				  if (exist){
					  exist.quantity++;
					  this.store(list);
					  this.trigger("increment", product);
				  }
				  return list;
			  },
			  decrement:function(product){
				 
				  var list = this.list();
				  var exist = this.match(product,list);
				  if (exist){
					  if (exist.quantity == 1){
						  this.destroy(product,list);
					  } else {
						  exist.quantity--;
						  this.store(list);
						  this.trigger("decrement", product);
						  
					  }
				  }
				  return list;
			  },
			  destroy:function(product,products){
				  var list = products || this.list();
				  //var exist = this.match(product.id,list);
				  for (var i in list){
					  if (this.eq(product,list[i])){
						  //delete list[i];
						  list.splice(i,1);
						  this.store(list);
						  this.trigger("destroy", product);
						  break;
					  }
				  }
				  return list;
			  },
			  destroyAll:function(){
				  //name, path, domain, secure)
				  cookieHelper.unset(CART_NAME,'/',domain,false);
			  },
			  trigger:function(event,params){
				  $win.trigger(event+".cart.maggiemaostudio",params);
			  },
			  match:function(product,list){
				  for (var i in list){
					  if (this.eq(product, list[i])){
						  return list[i];
					  }
				  }
			  },
			  eq:function(p1,p2){
				  function equals(v1,v2){
					  //验证是否都有值或者
					  if (!!v1 === false && !!v2 === false){
						  //空值("",undefined,null)
						  return true
					  } else  if (!!v1 === true && !!v2 === true && v1 == v2){
						  //有值
						  return true;
					  } else {
						  return false;
					  }
					  
				  }
				  return equals(p1.id,p2.id) && equals(p1.size_id,p2.size_id) && equals(p1.color_id,p2.color_id);
			  },
			  get:function(product){
				  var list = this.list();
				  return this.match(product,list);
			  },
			  list:function(){
				  var value = cookieHelper.get(CART_NAME)
				  if (!value){
					  return [];
				  }
				  return JSON.parse(value);
			  },
			  store:function(products){
				  var value = JSON.stringify(products);
				  var days = 30;
				  var exp = new Date(); 
				  exp.setTime(exp.getTime() + days*24*60*60*1000);
				  if (domain){
					  //,domain,false
					  cookieHelper.set(CART_NAME, value, exp, "/",domain,false);
				  } else {
					  cookieHelper.set(CART_NAME, value, exp, "/");
				  }
				 
			  },
			  showCartList:function(list){
				  
			  }
			  
	  };
	  $(function(){
		  var cartPopoverListTpl = "<ul class='am-list am-list-static'>" + 
		      "{{#each this}}"+
			  "<li data-id='{{id}}' data-size_id='{{size_id}}' data-color_id='{{color_id}}'>"+
			  	"<div class='m-cart-item am-cf'>" + 
			  	   "<a href='{{url 'product/' id}}'>" +
			  		"<img src='{{imgurl image 48 56}}'></img>" + 
			  		"<div class='m-cart-item-bd'>" +
			  			"<div class='name'>{{enname}}</div>"+
			  			"<div class='name'>{{name}}</div>" +
			  			"<div class='price'>￥{{fnumber price}}</div>"+
			  		"</div>" +
			  		"</a>" + 
			  		"<span class='am-close m-cart-item-close'>&times;</span>" + 
			  	"</div>" +
			  "</li>" + 
			  "{{/each}}" +
		  "</ul>";
		  var cartPopoverTpl="<div class='am-popover m-cart-popover'><div class='am-popover-inner m-cart-popover-inner'></div></div>"
		  var cartPopover = $(".m-nav-cart").popover({
			    content: "<div class='m-cart-list'>" +
			    		"<div class='m-cart-list-bd'>" +
			    			"<div class='m-cart-list-loading'>" +
			    			"<span class='am-icon-spinner am-icon-spin'></span>" +
			    			"</div>" +
			    		"</div><button type='button' class='m-btn m-btn-pure' id='view_cart-btn'>查看购物车</button>" +
			    		"</div>",
			    trigger:'hover',
			    tpl:cartPopoverTpl,
			    spacing:4
		  });
		  
		  var favoriteTpl = "<div class='m-favorite-success'><span>已成功添加至收藏夹 </span><a href='"+$.config.base+"user/favorite-list'><span class='m-go-favorite'>查看我的收藏夹</span></a></div>";
		  $(".m-nav-cart").on("open.popover.amui",function(){
			  //$(".m-notice-popover").css("opacity",0.85);
			  if ($(".m-cart-popover").find("ul").length == 0){
				  drawCartList();
			  }
		  });
		  $(document)
		  	.on("click.cart",".m-nav-cart,.m-cart-popover,#m-add-product-btn",function(e){
		  		e.stopPropagation();
		  	})
		  	.on("click.cart",function(){
			  $(".m-nav-cart").popover("close");
		  });
		  
		  $win.on("destroy.cart.maggiemaostudio",function(e,data){
			  $(".m-cart-popover").find("li").each(function(i,e){
				  var curData = $(this).data();
				  if ($.cart.eq(data,curData)){
					  $(this).remove();
					  return false;
				  }
			  });
			  var length = $(".m-cart-popover").find("li").length;
			  if (length == 0){
				  drawEmptyCart();
			  }
			  drawCartSize();
		  });
		  $win.on("add.cart.maggiemaostudio",function(e,data){
			  $(".m-nav-cart").popover("open");
			  drawCartSize();
			  drawCartList();
			  //显示购物篮
			  setTimeout(function(){
				  $(".m-nav-cart").popover("close");
			  },$.config.cart_timeout);
		  });
		  
		  /**
		   * 获取product数据，如果产品有尺寸和颜色，需要选择，如果没有选择返回null
		   */
		  function validAndReturnProduct($product){
			  var $select = $product.find("select");
			  var unselect = false;
			  //验证是否选择规格和颜色
			  var product = $product.data();
			  if ($select.length != 0){
				  $select.each(function(i,e){
					  var value = $(this).val();
					  var text = $(this).find("option:selected").text();
				      var name = $(this).attr("name");
					  //值不为空
					  if (value != '-'){
						  if (name=='size'){
							  product['size_id'] = value;
							  product['size'] = text;
						  } else {
							  product['color_id'] = value;
							  product['color'] = text;
						  }
						  $(this).next().find('button').removeClass("warn");
					  } else {
						  unselect = true;
						  $(this).next().find('button').addClass("warn");
					  }
				  });
			  }
			  
			  if (unselect){
				  return null;
			  } else {
				  return product;
			  }
		  }
		  //添加商品按钮
		  $(document).on("click","#m-add-product-btn",function(e){
			  var $btn = $(this);
			  if ($btn.is('disabled')){
				  return;
			  }
			  var $product = $btn.closest(".m-product-detail");
			  var product = validAndReturnProduct($product);
			  if (product){
				  //移除bs.affix字段
				  product = $.extend({},product);
				  delete product["bs.affix"];
				  var products = $.cart.add(product);
				  /*
				  $(".m-nav-cart").popover("open");
				  drawCartSize();
				  drawCartList();
				  //显示购物篮
				  setTimeout(function(){
					  $(".m-nav-cart").popover("close");
				  },$.config.cart_timeout);*/
			  }
			  //
		  });
		  
		  //删除商品
		  $(document).on("click",".m-cart-item-close",function(){
			  var $li = $(this).closest("li");
			  var data = $li.data();
			  $.cart.destroy(data);
		  });
		  
		  //收藏商品
		  $(document).on("click","#m-favorite-product",function(){
			  if (!$.config.login){
				  $.user.login();
				  return;
			  }
			  var $btn = $(this);
			  var $product = $btn.closest(".m-product-detail");
			  var product = validAndReturnProduct($product);
			  if (product){
				  delete product["bs.affix"];
				  //提交请求
				  $btn.button('loading');
				  $.post($.config.base+"product/favorite",product,function(data){
					  //$.boxer($(favoriteTpl));
					  $.dialog.show({
						  tpl:favoriteTpl,
						  width:360
					  });
					  $btn.button('reset');
				  });
			  }
		  });
		  //查看购物篮
		  $("#view_cart-btn").on("click",function(){
			  window.location.href = $.config.base + 'cart';
		  });
		 
		  function drawCartSize(){
			  var list = $.cart.list();
			  var size = 0;
			  $.each(list,function(i,p){
				  size += p.quantity;
			  });
			  $(".m-cart-size").text(" ("+size+")");
		  }
		  function drawEmptyCart(){
			  $('.m-cart-list-bd').html("<span class='no-product'>暂时没有添加商品</span>");
			  $(".m-cart-list").find("button").attr("disable","disable");
		  }
		  function drawCartList(){
			  var products = $.cart.list();
			  if (products.length == 0){
				  drawEmptyCart();
			  } else {
				  $(".m-cart-list").find("button").removeAttr("disable");
				  var template = Handlebars.compile(cartPopoverListTpl);
				  $('.m-cart-list-bd').html(template(products));
			  }
		  }
		 
		  drawCartSize();
	  });
})(jQuery,window);
(function($,window) {
	
	var confirmOptions={
			tpl:"<div class='am-modal am-modal-no-btn m-dialog' id='comfirm-dialog'>" + 
			      "<div class='am-modal-dialog'>" + 
			         "<div class='am-modal-hd'>" + 
			            "<a href='javascript: void(0)' class='am-close' data-am-modal-close>&times;</a>" + 
			         "</div>" + 
			         "<div class='am-modal-bd'>" + 
				         "<div class='m-dialog-confirm'>"+
							"<div class='m-dialog-hd'></div>" +
							"<div class='m-dialog-bd'></div>" +
							"<div class='m-dialog-footer am-g am-cf'>" +
								"<div class='am-u-md-6'>" +
									"<span class='m-btn m-btn-normal cancel'>取消</span>" +
								"</div>"+
								"<div class='am-u-md-6'>" +
									"<span class='m-btn m-btn-normal ok'>确定</span>" +
								"</div>" +
							"</div>" +
						"</div>" +
			         "</div>" + 
			       "</div>" +
			    "</div>",
				title:null,
				content:null,
				cancel:$.noop,
				ok:$.noop
			};
	
	$.dialog = {
			confirm:function(options){
				var opt = $.extend({},confirmOptions,options);
				
				if (!$("#comfirm-dialog").length){
					$("body").append(opt.tpl);
				}
				//var $content = $(opt.tpl);
				if (opt.title){
					$("#comfirm-dialog").find('.m-dialog-hd').html(opt.title);
				}
				$("#comfirm-dialog").find('.m-dialog-bd').html(opt.content);
				//$("#dialog").find(".am-modal-bd").html($content);
				
				$("#comfirm-dialog").modal({
					width:360
				});
				//$.boxer($content);
				$("#comfirm-dialog").on('click','.ok',function(){
					opt.ok();
					//$.boxer('close');
					$("#comfirm-dialog").modal("close");
				});
				$("#comfirm-dialog").on('click','.cancel',function(){
					opt.cancel();
					//$.boxer('close');
					$("#comfirm-dialog").modal("close");
				});
			},
			show:function(options){
				$("#dialog").find(".am-modal-bd").html(options.tpl);
				this.clear();
				if (options.events){
					for (key in options.events){
						$('#dialog').on(key + '.modal.amui',options.events[key]);
					}
				}
				$("#dialog").modal(options);
			},
			clear:function(){
				$("#dialog").off("open.modal.amui");//open 方法被调用是立即触发
				$("#dialog").off("opened.modal.amui");//	Modal 窗口打开完成以后触发（CSS 动画执行完成）
				$("#dialog").off("close.modal.amui");//	close 方法被调用是立即触发
				$("#dialog").off("closed.modal.amui");//
			},
			close:function(){
				$("#dialog").modal("close");
			}
	};
	
})(jQuery,window);

/*

Supersized - Fullscreen Slideshow jQuery Plugin
Version : 3.2.7
Site	: www.buildinternet.com/project/supersized

Author	: Sam Dunn
Company : One Mighty Roar (www.onemightyroar.com)
License : MIT License / GPL License

*/

(function($){

/* Place Supersized Elements
----------------------------*/
$(document).ready(function() {
	$('body').append('<div id="supersized-loader"></div><ul id="supersized"></ul>');
});


$.supersized = function(options){
	
	/* Variables
	----------------------------*/
	var el = '#supersized',
    	base = this;
    // Access to jQuery and DOM versions of element
    base.$el = $(el);
    base.el = el;
    vars = $.supersized.vars;
    // Add a reverse reference to the DOM object
    base.$el.data("supersized", base);
    api = base.$el.data('supersized');
	
	base.init = function(){
    	// Combine options and vars
    	$.supersized.vars = $.extend($.supersized.vars, $.supersized.themeVars);
    	$.supersized.vars.options = $.extend({},$.supersized.defaultOptions, $.supersized.themeOptions, options);
        base.options = $.supersized.vars.options;
        
        base._build();
    };
    
    
    /* Build Elements
	----------------------------*/
    base._build = function(){
    	// Add in slide markers
    	var thisSlide = 0,
    		slideSet = '',
			markers = '',
			markerContent,
			thumbMarkers = '',
			thumbImage;
			
		while(thisSlide <= base.options.slides.length-1){
			//Determine slide link content
			switch(base.options.slide_links){
				case 'num':
					markerContent = thisSlide;
					break;
				case 'name':
					markerContent = base.options.slides[thisSlide].title;
					break;
				case 'blank':
					markerContent = '';
					break;
			}
			
			slideSet = slideSet+'<li class="slide-'+thisSlide+'"></li>';
			
			if(thisSlide == base.options.start_slide-1){
				// Slide links
				if (base.options.slide_links)markers = markers+'<li class="slide-link-'+thisSlide+' current-slide"><a>'+markerContent+'</a></li>';
				// Slide Thumbnail Links
				if (base.options.thumb_links){
					base.options.slides[thisSlide].thumb ? thumbImage = base.options.slides[thisSlide].thumb : thumbImage = base.options.slides[thisSlide].image;
					thumbMarkers = thumbMarkers+'<li class="thumb'+thisSlide+' current-thumb"><img src="'+thumbImage+'"/></li>';
				};
			}else{
				// Slide links
				if (base.options.slide_links) markers = markers+'<li class="slide-link-'+thisSlide+'" ><a>'+markerContent+'</a></li>';
				// Slide Thumbnail Links
				if (base.options.thumb_links){
					base.options.slides[thisSlide].thumb ? thumbImage = base.options.slides[thisSlide].thumb : thumbImage = base.options.slides[thisSlide].image;
					thumbMarkers = thumbMarkers+'<li class="thumb'+thisSlide+'"><img src="'+thumbImage+'"/></li>';
				};
			}
			thisSlide++;
		}
		
		if (base.options.slide_links) $(vars.slide_list).html(markers);
		if (base.options.thumb_links && vars.thumb_tray.length){
			$(vars.thumb_tray).append('<ul id="'+vars.thumb_list.replace('#','')+'">'+thumbMarkers+'</ul>');
		}
		
		$(base.el).append(slideSet);
		
		// Add in thumbnails
		if (base.options.thumbnail_navigation){
			// Load previous thumbnail
			vars.current_slide - 1 < 0  ? prevThumb = base.options.slides.length - 1 : prevThumb = vars.current_slide - 1;
			$(vars.prev_thumb).show().html($("<img/>").attr("src", base.options.slides[prevThumb].image));
			
			// Load next thumbnail
			vars.current_slide == base.options.slides.length - 1 ? nextThumb = 0 : nextThumb = vars.current_slide + 1;
			$(vars.next_thumb).show().html($("<img/>").attr("src", base.options.slides[nextThumb].image));
		}
		
        base._start(); // Get things started
    };
    
    
    /* Initialize
	----------------------------*/
	base._start = function(){
		
		// Determine if starting slide random
		if (base.options.start_slide){
			vars.current_slide = base.options.start_slide - 1;
		}else{
			vars.current_slide = Math.floor(Math.random()*base.options.slides.length);	// Generate random slide number
		}
		
		// If links should open in new window
		var linkTarget = base.options.new_window ? ' target="_blank"' : '';
		
		// Set slideshow quality (Supported only in FF and IE, no Webkit)
		if (base.options.performance == 3){
			base.$el.addClass('speed'); 		// Faster transitions
		} else if ((base.options.performance == 1) || (base.options.performance == 2)){
			base.$el.addClass('quality');	// Higher image quality
		}
					
		// Shuffle slide order if needed		
		if (base.options.random){
			arr = base.options.slides;
			for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);	// Fisher-Yates shuffle algorithm (jsfromhell.com/array/shuffle)
		    base.options.slides = arr;
		}
		
		/*-----Load initial set of images-----*/

		if (base.options.slides.length > 1){
			if(base.options.slides.length > 2){
				// Set previous image
				vars.current_slide - 1 < 0  ? loadPrev = base.options.slides.length - 1 : loadPrev = vars.current_slide - 1;	// If slide is 1, load last slide as previous
				var imageLink = (base.options.slides[loadPrev].url) ? "href='" + base.options.slides[loadPrev].url + "'" : "";
			
				var imgPrev = $('<img src="'+base.options.slides[loadPrev].image+'"/>');
				var slidePrev = base.el+' li:eq('+loadPrev+')';
				imgPrev.appendTo(slidePrev).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading prevslide');
			
				imgPrev.load(function(){
					$(this).data('origWidth', $(this).width()).data('origHeight', $(this).height());
					base.resizeNow();	// Resize background image
				});	// End Load
			}
		} else {
			// Slideshow turned off if there is only one slide
			base.options.slideshow = 0;
		}
		
		// Set current image
		imageLink = (api.getField('url')) ? "href='" + api.getField('url') + "'" : "";
		var img = $('<img src="'+api.getField('image')+'"/>');
		
		var slideCurrent= base.el+' li:eq('+vars.current_slide+')';
		img.appendTo(slideCurrent).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading activeslide');
		
		img.load(function(){
			base._origDim($(this));
			base.resizeNow();	// Resize background image
			base.launch();
			if( typeof theme != 'undefined' && typeof theme._init == "function" ) theme._init();	// Load Theme
		});
		
		if (base.options.slides.length > 1){
			// Set next image
			vars.current_slide == base.options.slides.length - 1 ? loadNext = 0 : loadNext = vars.current_slide + 1;	// If slide is last, load first slide as next
			imageLink = (base.options.slides[loadNext].url) ? "href='" + base.options.slides[loadNext].url + "'" : "";
			
			var imgNext = $('<img src="'+base.options.slides[loadNext].image+'"/>');
			var slideNext = base.el+' li:eq('+loadNext+')';
			imgNext.appendTo(slideNext).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading');
			
			imgNext.load(function(){
				$(this).data('origWidth', $(this).width()).data('origHeight', $(this).height());
				base.resizeNow();	// Resize background image
			});	// End Load
		}
		/*-----End load initial images-----*/
		
		//  Hide elements to be faded in
		base.$el.css('visibility','hidden');
		$('.load-item').hide();
		
	};
	
	
	/* Launch Supersized
	----------------------------*/
	base.launch = function(){
	
		base.$el.css('visibility','visible');
		$('#supersized-loader').remove();		//Hide loading animation
		
		// Call theme function for before slide transition
		if( typeof theme != 'undefined' && typeof theme.beforeAnimation == "function" ) theme.beforeAnimation('next');
		$('.load-item').show();
		
		// Keyboard Navigation
		if (base.options.keyboard_nav){
			$(document.documentElement).keyup(function (event) {
			
				if(vars.in_animation) return false;		// Abort if currently animating
				if($(document.activeElement).is("input, textarea")) return false; // Abort if active element is an input or a textarea.
				
				// Left Arrow or Down Arrow
				if ((event.keyCode == 37) || (event.keyCode == 40)) {
					clearInterval(vars.slideshow_interval);	// Stop slideshow, prevent buildup
					base.prevSlide();
				
				// Right Arrow or Up Arrow
				} else if ((event.keyCode == 39) || (event.keyCode == 38)) {
					clearInterval(vars.slideshow_interval);	// Stop slideshow, prevent buildup
					base.nextSlide();
				
				// Spacebar	
				} else if (event.keyCode == 32 && !vars.hover_pause) {
					clearInterval(vars.slideshow_interval);	// Stop slideshow, prevent buildup
					base.playToggle();
				}
			
			});
		}
		
		// Pause when hover on image
		if (base.options.slideshow && base.options.pause_hover){
			$(base.el).hover(function() {
				if(vars.in_animation) return false;		// Abort if currently animating
		   			vars.hover_pause = true;	// Mark slideshow paused from hover
		   			if(!vars.is_paused){
		   				vars.hover_pause = 'resume';	// It needs to resume afterwards
		   				base.playToggle();
		   			}
		   	}, function() {
				if(vars.hover_pause == 'resume'){
					base.playToggle();
					vars.hover_pause = false;
				}
		   	});
		}
		
		if (base.options.slide_links){
			// Slide marker clicked
			$(vars.slide_list+'> li').click(function(){
			
				index = $(vars.slide_list+'> li').index(this);
				targetSlide = index + 1;
				
				base.goTo(targetSlide);
				return false;
				
			});
		}
		
		// Thumb marker clicked
		if (base.options.thumb_links){
			$(vars.thumb_list+'> li').click(function(){
			
				index = $(vars.thumb_list+'> li').index(this);
				targetSlide = index + 1;
				
				api.goTo(targetSlide);
				return false;
				
			});
		}
		
		// Start slideshow if enabled
		if (base.options.slideshow && base.options.slides.length > 1){
    		
    		// Start slideshow if autoplay enabled
    		if (base.options.autoplay && base.options.slides.length > 1){
    			vars.slideshow_interval = setInterval(base.nextSlide, base.options.slide_interval);	// Initiate slide interval
			}else{
				vars.is_paused = true;	// Mark as paused
			}
			
			//Prevent navigation items from being dragged					
			$('.load-item img').bind("contextmenu mousedown",function(){
				return false;
			});
							
		}
		
		// Adjust image when browser is resized
		$(window).resize(function(){
    		base.resizeNow();
		});
		
	};
    
    
    /* Resize Images
	----------------------------*/
	base.resizeNow = function(){
		
		return base.$el.each(function() {
	  		//  Resize each image seperately
	  		$('img', base.el).each(function(){
	  			
				thisSlide = $(this);
				var ratio = (thisSlide.data('origHeight')/thisSlide.data('origWidth')).toFixed(2);	// Define image ratio
				
				// Gather browser size
				var browserwidth = base.$el.width(),
					browserheight = base.$el.height(),
					offset;
				
				/*-----Resize Image-----*/
				if (base.options.fit_always){	// Fit always is enabled
					if ((browserheight/browserwidth) > ratio){
						resizeWidth();
					} else {
						resizeHeight();
					}
				}else{	// Normal Resize
					if ((browserheight <= base.options.min_height) && (browserwidth <= base.options.min_width)){	// If window smaller than minimum width and height
					
						if ((browserheight/browserwidth) > ratio){
							base.options.fit_landscape && ratio < 1 ? resizeWidth(true) : resizeHeight(true);	// If landscapes are set to fit
						} else {
							base.options.fit_portrait && ratio >= 1 ? resizeHeight(true) : resizeWidth(true);		// If portraits are set to fit
						}
					
					} else if (browserwidth <= base.options.min_width){		// If window only smaller than minimum width
					
						if ((browserheight/browserwidth) > ratio){
							base.options.fit_landscape && ratio < 1 ? resizeWidth(true) : resizeHeight();	// If landscapes are set to fit
						} else {
							base.options.fit_portrait && ratio >= 1 ? resizeHeight() : resizeWidth(true);		// If portraits are set to fit
						}
						
					} else if (browserheight <= base.options.min_height){	// If window only smaller than minimum height
					
						if ((browserheight/browserwidth) > ratio){
							base.options.fit_landscape && ratio < 1 ? resizeWidth() : resizeHeight(true);	// If landscapes are set to fit
						} else {
							base.options.fit_portrait && ratio >= 1 ? resizeHeight(true) : resizeWidth();		// If portraits are set to fit
						}
					
					} else {	// If larger than minimums
						
						if ((browserheight/browserwidth) > ratio){
							base.options.fit_landscape && ratio < 1 ? resizeWidth() : resizeHeight();	// If landscapes are set to fit
						} else {
							base.options.fit_portrait && ratio >= 1 ? resizeHeight() : resizeWidth();		// If portraits are set to fit
						}
						
					}
				}
				/*-----End Image Resize-----*/
				
				
				/*-----Resize Functions-----*/
				
				function resizeWidth(minimum){
					if (minimum){	// If minimum height needs to be considered
						if(thisSlide.width() < browserwidth || thisSlide.width() < base.options.min_width ){
							if (thisSlide.width() * ratio >= base.options.min_height){
								thisSlide.width(base.options.min_width);
					    		thisSlide.height(thisSlide.width() * ratio);
					    	}else{
					    		resizeHeight();
					    	}
					    }
					}else{
						if (base.options.min_height >= browserheight && !base.options.fit_landscape){	// If minimum height needs to be considered
							if (browserwidth * ratio >= base.options.min_height || (browserwidth * ratio >= base.options.min_height && ratio <= 1)){	// If resizing would push below minimum height or image is a landscape
								thisSlide.width(browserwidth);
								thisSlide.height(browserwidth * ratio);
							} else if (ratio > 1){		// Else the image is portrait
								thisSlide.height(base.options.min_height);
								thisSlide.width(thisSlide.height() / ratio);
							} else if (thisSlide.width() < browserwidth) {
								thisSlide.width(browserwidth);
					    		thisSlide.height(thisSlide.width() * ratio);
							}
						}else{	// Otherwise, resize as normal
							thisSlide.width(browserwidth);
							thisSlide.height(browserwidth * ratio);
						}
					}
				};
				
				function resizeHeight(minimum){
					if (minimum){	// If minimum height needs to be considered
						if(thisSlide.height() < browserheight){
							if (thisSlide.height() / ratio >= base.options.min_width){
								thisSlide.height(base.options.min_height);
								thisSlide.width(thisSlide.height() / ratio);
							}else{
								resizeWidth(true);
							}
						}
					}else{	// Otherwise, resized as normal
						if (base.options.min_width >= browserwidth){	// If minimum width needs to be considered
							if (browserheight / ratio >= base.options.min_width || ratio > 1){	// If resizing would push below minimum width or image is a portrait
								thisSlide.height(browserheight);
								thisSlide.width(browserheight / ratio);
							} else if (ratio <= 1){		// Else the image is landscape
								thisSlide.width(base.options.min_width);
					    		thisSlide.height(thisSlide.width() * ratio);
							}
						}else{	// Otherwise, resize as normal
							thisSlide.height(browserheight);
							thisSlide.width(browserheight / ratio);
						}
					}
				};
				
				/*-----End Resize Functions-----*/
				
				if (thisSlide.parents('li').hasClass('image-loading')){
					$('.image-loading').removeClass('image-loading');
				}
				
				// Horizontally Center
				if (base.options.horizontal_center){
					$(this).css('left', (browserwidth - $(this).width())/2);
				}
				
				// Vertically Center
				if (base.options.vertical_center){
					$(this).css('top', (browserheight - $(this).height())/2);
				}
				
			});
			
			// Basic image drag and right click protection
			if (base.options.image_protect){
				
				$('img', base.el).bind("contextmenu mousedown",function(){
					return false;
				});
			
			}
			
			return false;
			
		});
		
	};
    
    
    /* Next Slide
	----------------------------*/
	base.nextSlide = function(){
		
		if(vars.in_animation || !api.options.slideshow) return false;		// Abort if currently animating
			else vars.in_animation = true;		// Otherwise set animation marker
			
	    clearInterval(vars.slideshow_interval);	// Stop slideshow
	    
	    var slides = base.options.slides,					// Pull in slides array
			liveslide = base.$el.find('.activeslide');		// Find active slide
			$('.prevslide').removeClass('prevslide');
			liveslide.removeClass('activeslide').addClass('prevslide');	// Remove active class & update previous slide
				
		// Get the slide number of new slide
		vars.current_slide + 1 == base.options.slides.length ? vars.current_slide = 0 : vars.current_slide++;
		
	    var nextslide = $(base.el+' li:eq('+vars.current_slide+')'),
	    	prevslide = base.$el.find('.prevslide');
		
		// If hybrid mode is on drop quality for transition
		if (base.options.performance == 1) base.$el.removeClass('quality').addClass('speed');	
		
		
		/*-----Load Image-----*/
		
		loadSlide = false;

		vars.current_slide == base.options.slides.length - 1 ? loadSlide = 0 : loadSlide = vars.current_slide + 1;	// Determine next slide

		var targetList = base.el+' li:eq('+loadSlide+')';
		if (!$(targetList).html()){
			
			// If links should open in new window
			var linkTarget = base.options.new_window ? ' target="_blank"' : '';
			
			imageLink = (base.options.slides[loadSlide].url) ? "href='" + base.options.slides[loadSlide].url + "'" : "";	// If link exists, build it
			var img = $('<img src="'+base.options.slides[loadSlide].image+'"/>'); 
			
			img.appendTo(targetList).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading').css('visibility','hidden');
			
			img.load(function(){
				base._origDim($(this));
				base.resizeNow();
			});	// End Load
		};
					
		// Update thumbnails (if enabled)
		if (base.options.thumbnail_navigation == 1){
		
			// Load previous thumbnail
			vars.current_slide - 1 < 0  ? prevThumb = base.options.slides.length - 1 : prevThumb = vars.current_slide - 1;
			$(vars.prev_thumb).html($("<img/>").attr("src", base.options.slides[prevThumb].image));
		
			// Load next thumbnail
			nextThumb = loadSlide;
			$(vars.next_thumb).html($("<img/>").attr("src", base.options.slides[nextThumb].image));
			
		}
		
		
		
		/*-----End Load Image-----*/
		
		
		// Call theme function for before slide transition
		if( typeof theme != 'undefined' && typeof theme.beforeAnimation == "function" ) theme.beforeAnimation('next');
		
		//Update slide markers
		if (base.options.slide_links){
			$('.current-slide').removeClass('current-slide');
			$(vars.slide_list +'> li' ).eq(vars.current_slide).addClass('current-slide');
		}
	    
	    nextslide.css('visibility','hidden').addClass('activeslide');	// Update active slide
	    
    	switch(base.options.transition){
    		case 0: case 'none':	// No transition
    		    nextslide.css('visibility','visible'); vars.in_animation = false; base.afterAnimation();
    		    break;
    		case 1: case 'fade':	// Fade
    		    nextslide.css({opacity : 0, 'visibility': 'visible'}).animate({opacity : 1, avoidTransforms : false}, base.options.transition_speed, function(){ base.afterAnimation(); });
    		    break;
    		case 2: case 'slideTop':	// Slide Top
    		    nextslide.css({top : -base.$el.height(), 'visibility': 'visible'}).animate({ top:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    		    break;
    		case 3: case 'slideRight':	// Slide Right
    			nextslide.css({left : base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 4: case 'slideBottom': // Slide Bottom
    			nextslide.css({top : base.$el.height(), 'visibility': 'visible'}).animate({ top:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 5: case 'slideLeft':  // Slide Left
    			nextslide.css({left : -base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 6: case 'carouselRight':	// Carousel Right
    			nextslide.css({left : base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
				liveslide.animate({ left: -base.$el.width(), avoidTransforms : false }, base.options.transition_speed );
    			break;
    		case 7: case 'carouselLeft':   // Carousel Left
    			nextslide.css({left : -base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
				liveslide.animate({ left: base.$el.width(), avoidTransforms : false }, base.options.transition_speed );
    			break;
    	}
	    return false;	
	};
	
	
	/* Previous Slide
	----------------------------*/
	base.prevSlide = function(){
	
		if(vars.in_animation || !api.options.slideshow) return false;		// Abort if currently animating
			else vars.in_animation = true;		// Otherwise set animation marker
		
		clearInterval(vars.slideshow_interval);	// Stop slideshow
		
		var slides = base.options.slides,					// Pull in slides array
			liveslide = base.$el.find('.activeslide');		// Find active slide
			$('.prevslide').removeClass('prevslide');
			liveslide.removeClass('activeslide').addClass('prevslide');		// Remove active class & update previous slide
		
		// Get current slide number
		vars.current_slide == 0 ?  vars.current_slide = base.options.slides.length - 1 : vars.current_slide-- ;
			
	    var nextslide =  $(base.el+' li:eq('+vars.current_slide+')'),
	    	prevslide =  base.$el.find('.prevslide');
		
		// If hybrid mode is on drop quality for transition
		if (base.options.performance == 1) base.$el.removeClass('quality').addClass('speed');	
		
		
		/*-----Load Image-----*/
		
		loadSlide = vars.current_slide;
		
		var targetList = base.el+' li:eq('+loadSlide+')';
		if (!$(targetList).html()){
			// If links should open in new window
			var linkTarget = base.options.new_window ? ' target="_blank"' : '';
			imageLink = (base.options.slides[loadSlide].url) ? "href='" + base.options.slides[loadSlide].url + "'" : "";	// If link exists, build it
			var img = $('<img src="'+base.options.slides[loadSlide].image+'"/>'); 
			
			img.appendTo(targetList).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading').css('visibility','hidden');
			
			img.load(function(){
				base._origDim($(this));
				base.resizeNow();
			});	// End Load
		};
		
		// Update thumbnails (if enabled)
		if (base.options.thumbnail_navigation == 1){
		
			// Load previous thumbnail
			//prevThumb = loadSlide;
			loadSlide == 0 ? prevThumb = base.options.slides.length - 1 : prevThumb = loadSlide - 1;
			$(vars.prev_thumb).html($("<img/>").attr("src", base.options.slides[prevThumb].image));
			
			// Load next thumbnail
			vars.current_slide == base.options.slides.length - 1 ? nextThumb = 0 : nextThumb = vars.current_slide + 1;
			$(vars.next_thumb).html($("<img/>").attr("src", base.options.slides[nextThumb].image));
		}
		
		/*-----End Load Image-----*/
		
		
		// Call theme function for before slide transition
		if( typeof theme != 'undefined' && typeof theme.beforeAnimation == "function" ) theme.beforeAnimation('prev');
		
		//Update slide markers
		if (base.options.slide_links){
			$('.current-slide').removeClass('current-slide');
			$(vars.slide_list +'> li' ).eq(vars.current_slide).addClass('current-slide');
		}
		
	    nextslide.css('visibility','hidden').addClass('activeslide');	// Update active slide
	    
	    switch(base.options.transition){
    		case 0: case 'none':	// No transition
    		    nextslide.css('visibility','visible'); vars.in_animation = false; base.afterAnimation();
    		    break;
    		case 1: case 'fade':	// Fade
    		  	nextslide.css({opacity : 0, 'visibility': 'visible'}).animate({opacity : 1, avoidTransforms : false}, base.options.transition_speed, function(){ base.afterAnimation(); });
    		    break;
    		case 2: case 'slideTop':	// Slide Top (reverse)
    		    nextslide.css({top : base.$el.height(), 'visibility': 'visible'}).animate({ top:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    		    break;
    		case 3: case 'slideRight':	// Slide Right (reverse)
    			nextslide.css({left : -base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 4: case 'slideBottom': // Slide Bottom (reverse)
    			nextslide.css({top : -base.$el.height(), 'visibility': 'visible'}).animate({ top:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 5: case 'slideLeft':  // Slide Left (reverse)
    			nextslide.css({left : base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
    			break;
    		case 6: case 'carouselRight':	// Carousel Right (reverse)
    			nextslide.css({left : -base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
				liveslide.css({left : 0}).animate({ left: base.$el.width(), avoidTransforms : false}, base.options.transition_speed );
    			break;
    		case 7: case 'carouselLeft':   // Carousel Left (reverse)
    			nextslide.css({left : base.$el.width(), 'visibility': 'visible'}).animate({ left:0, avoidTransforms : false }, base.options.transition_speed, function(){ base.afterAnimation(); });
				liveslide.css({left : 0}).animate({ left: -base.$el.width(), avoidTransforms : false }, base.options.transition_speed );
    			break;
    	}
	    return false;	
	};
	
	
	/* Play/Pause Toggle
	----------------------------*/
	base.playToggle = function(){
	
		if (vars.in_animation || !api.options.slideshow) return false;		// Abort if currently animating
		
		if (vars.is_paused){
			
			vars.is_paused = false;
			
			// Call theme function for play
			if( typeof theme != 'undefined' && typeof theme.playToggle == "function" ) theme.playToggle('play');
			
			// Resume slideshow
        	vars.slideshow_interval = setInterval(base.nextSlide, base.options.slide_interval);
        	  
    	}else{
    		
    		vars.is_paused = true;
    		
    		// Call theme function for pause
    		if( typeof theme != 'undefined' && typeof theme.playToggle == "function" ) theme.playToggle('pause');
    		
    		// Stop slideshow
    		clearInterval(vars.slideshow_interval);	
   		
   		}
	    
	    return false;
		
	};
	
	
	/* Go to specific slide
	----------------------------*/
	base.goTo = function(targetSlide){
		if (vars.in_animation || !api.options.slideshow) return false;		// Abort if currently animating
		
		var totalSlides = base.options.slides.length;
		
		// If target outside range
		if(targetSlide < 0){
			targetSlide = totalSlides;
		}else if(targetSlide > totalSlides){
			targetSlide = 1;
		}
		targetSlide = totalSlides - targetSlide + 1;
		
		clearInterval(vars.slideshow_interval);	// Stop slideshow, prevent buildup
		
		// Call theme function for goTo trigger
		if (typeof theme != 'undefined' && typeof theme.goTo == "function" ) theme.goTo();
		
		if (vars.current_slide == totalSlides - targetSlide){
			if(!(vars.is_paused)){
				vars.slideshow_interval = setInterval(base.nextSlide, base.options.slide_interval);
			} 
			return false;
		}
		
		// If ahead of current position
		if(totalSlides - targetSlide > vars.current_slide ){
			
			// Adjust for new next slide
			vars.current_slide = totalSlides-targetSlide-1;
			vars.update_images = 'next';
			base._placeSlide(vars.update_images);
			
		//Otherwise it's before current position
		}else if(totalSlides - targetSlide < vars.current_slide){
			
			// Adjust for new prev slide
			vars.current_slide = totalSlides-targetSlide+1;
			vars.update_images = 'prev';
		    base._placeSlide(vars.update_images);
		    
		}
		
		// set active markers
		if (base.options.slide_links){
			$(vars.slide_list +'> .current-slide').removeClass('current-slide');
			$(vars.slide_list +'> li').eq((totalSlides-targetSlide)).addClass('current-slide');
		}
		
		if (base.options.thumb_links){
			$(vars.thumb_list +'> .current-thumb').removeClass('current-thumb');
			$(vars.thumb_list +'> li').eq((totalSlides-targetSlide)).addClass('current-thumb');
		}
		
	};
    
    
    /* Place Slide
	----------------------------*/
    base._placeSlide = function(place){
			
		// If links should open in new window
		var linkTarget = base.options.new_window ? ' target="_blank"' : '';
		
		loadSlide = false;
		
		if (place == 'next'){
			
			vars.current_slide == base.options.slides.length - 1 ? loadSlide = 0 : loadSlide = vars.current_slide + 1;	// Determine next slide
			
			var targetList = base.el+' li:eq('+loadSlide+')';
			
			if (!$(targetList).html()){
				// If links should open in new window
				var linkTarget = base.options.new_window ? ' target="_blank"' : '';
				
				imageLink = (base.options.slides[loadSlide].url) ? "href='" + base.options.slides[loadSlide].url + "'" : "";	// If link exists, build it
				var img = $('<img src="'+base.options.slides[loadSlide].image+'"/>'); 
				
				img.appendTo(targetList).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading').css('visibility','hidden');
				
				img.load(function(){
					base._origDim($(this));
					base.resizeNow();
				});	// End Load
			};
			
			base.nextSlide();
			
		}else if (place == 'prev'){
		
			vars.current_slide - 1 < 0  ? loadSlide = base.options.slides.length - 1 : loadSlide = vars.current_slide - 1;	// Determine next slide
			
			var targetList = base.el+' li:eq('+loadSlide+')';
			
			if (!$(targetList).html()){
				// If links should open in new window
				var linkTarget = base.options.new_window ? ' target="_blank"' : '';
				
				imageLink = (base.options.slides[loadSlide].url) ? "href='" + base.options.slides[loadSlide].url + "'" : "";	// If link exists, build it
				var img = $('<img src="'+base.options.slides[loadSlide].image+'"/>'); 
				
				img.appendTo(targetList).wrap('<a ' + imageLink + linkTarget + '></a>').parent().parent().addClass('image-loading').css('visibility','hidden');
				
				img.load(function(){
					base._origDim($(this));
					base.resizeNow();
				});	// End Load
			};
			base.prevSlide();
		}
		
	};
	
	
	/* Get Original Dimensions
	----------------------------*/
	base._origDim = function(targetSlide){
		targetSlide.data('origWidth', targetSlide.width()).data('origHeight', targetSlide.height());
	};
	
	
	/* After Slide Animation
	----------------------------*/
	base.afterAnimation = function(){
		
		// If hybrid mode is on swap back to higher image quality
		if (base.options.performance == 1){
	    	base.$el.removeClass('speed').addClass('quality');
		}
		
		// Update previous slide
		if (vars.update_images){
			vars.current_slide - 1 < 0  ? setPrev = base.options.slides.length - 1 : setPrev = vars.current_slide-1;
			vars.update_images = false;
			$('.prevslide').removeClass('prevslide');
			$(base.el+' li:eq('+setPrev+')').addClass('prevslide');
		}
		
		vars.in_animation = false;
		
		// Resume slideshow
		if (!vars.is_paused && base.options.slideshow){
			vars.slideshow_interval = setInterval(base.nextSlide, base.options.slide_interval);
			if (base.options.stop_loop && vars.current_slide == base.options.slides.length - 1 ) base.playToggle();
		}
		
		// Call theme function for after slide transition
		if (typeof theme != 'undefined' && typeof theme.afterAnimation == "function" ) theme.afterAnimation();
		
		return false;
	
	};
	
	base.getField = function(field){
		return base.options.slides[vars.current_slide][field];
	};
	
    // Make it go!
    base.init();
};


/* Global Variables
----------------------------*/
$.supersized.vars = {

	// Elements							
	thumb_tray			:	'#thumb-tray',	// Thumbnail tray
	thumb_list			:	'#thumb-list',	// Thumbnail list
	slide_list          :   '#slide-list',	// Slide link list
	
	// Internal variables
	current_slide			:	0,			// Current slide number
	in_animation 			:	false,		// Prevents animations from stacking
	is_paused 				: 	false,		// Tracks paused on/off
	hover_pause				:	false,		// If slideshow is paused from hover
	slideshow_interval		:	false,		// Stores slideshow timer					
	update_images 			: 	false,		// Trigger to update images after slide jump
	options					:	{}			// Stores assembled options list
	
};


/* Default Options
----------------------------*/
$.supersized.defaultOptions = {

	// Functionality
	slideshow               :   1,			// Slideshow on/off
	autoplay				:	1,			// Slideshow starts playing automatically
	start_slide             :   1,			// Start slide (0 is random)
	stop_loop				:	0,			// Stops slideshow on last slide
	random					: 	0,			// Randomize slide order (Ignores start slide)
	slide_interval          :   5000,		// Length between transitions
	transition              :   1, 			// 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
	transition_speed		:	750,		// Speed of transition
	new_window				:	1,			// Image links open in new window/tab
	pause_hover             :   0,			// Pause slideshow on hover
	keyboard_nav            :   1,			// Keyboard navigation on/off
	performance				:	1,			// 0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed //  (Only works for Firefox/IE, not Webkit)
	image_protect			:	1,			// Disables image dragging and right click with Javascript
											   
	// Size & Position
	fit_always				:	0,			// Image will never exceed browser width or height (Ignores min. dimensions)
	fit_landscape			:   0,			// Landscape images will not exceed browser width
	fit_portrait         	:   1,			// Portrait images will not exceed browser height  			   
	min_width		        :   0,			// Min width allowed (in pixels)
	min_height		        :   0,			// Min height allowed (in pixels)
	horizontal_center       :   1,			// Horizontally center background
	vertical_center         :   1,			// Vertically center background
	
											   
	// Components							
	slide_links				:	1,			// Individual links for each slide (Options: false, 'num', 'name', 'blank')
	thumb_links				:	1,			// Individual thumb links for each slide
	thumbnail_navigation    :   0			// Thumbnail navigation
	
};

$.fn.supersized = function(options){
    return this.each(function(){
        (new $.supersized(options));
    });
};
	
})(jQuery);

(function($){
	
	var cookieHelper = $.AMUI.utils.cookie;
	var cookieKey = "$$____-seconds_remained";
	var cookies = {
			set:function(value,seconds){
				  var exp = new Date(); 
				  exp.setTime(exp.getTime() + seconds * 1000);
				  cookieHelper.set(cookieKey, value, exp, "/");
			},
			get:function(){
				return cookieHelper.get(cookieKey);
			}
	}
	
	
	var PhoneVerifyCode = function(options){
		var defaults = {
				phone:"",
				form:"",
				action:$.config.base+"verify-code",
				keeper:90,
				error:"",
				target:"",
		}
		this.options = $.extend({},defaults,options);
		
		var that = this;

		this.target = $(this.options.target);
		$(document).on("click",this.options.target,function(){
			if (that.verify()){
				that.post();
			}
			
		});
		var v = cookies.get();//获取cookie值
	    if(v>0){
	        this.countDown();//开始倒计时
	    }
	}
	
	PhoneVerifyCode.prototype = {
			verify:function(){
				var phonenum = this.getPhoneNum();
			    var myreg = /^1[34578]\d{9}$/; 
			    if(!myreg.test(phonenum)){ 
			        $(this.options.error).text("请输入有效的手机号码！");
			        return false; 
			    }else{
			        return true;
			    }
			},
			getPhoneNum:function(){
				return $(this.options.phone).val();
			},
			post:function(target){
				
//				this.target = target;
				var mobile = this.getPhoneNum();
				var that = this;
				
				var token = $(this.options.form).find("[name='_token']").val();
				$.post(this.options.action,{mobile:mobile,'_token':token},function(result){
				});
				cookies.set(90,90);//添加cookie记录,有效时间90s
				that.countDown();
			},
			countDown:function(){
				this.countValue = cookies.get();
			    if (!this.countValue) { 
			        this.target.removeAttr("disabled");    
			        this.target.text("获取验证码"); 
			        return;
			    } else { 
			    	 this.target.attr("disabled", true); 
			    	 this.target.text("重新发送(" + this.countValue + ")"); 
			    	 this.countValue--;
			    	 cookies.set(this.countValue,this.countValue + 1);
			    } 
			    var that = this;
			    setTimeout(function(){
			    	that.countDown();
			    },1000);
			}
	};
	
	$.phoneVerifyCode = function(options){
		return new PhoneVerifyCode(options);
	};
})(jQuery);
